package operation;

import Dao.MilkDao;
import interfac.MilkTeaOperation;
import pojo.MilkTeaProduct;

import java.util.Scanner;

public class AddMilkTeaOperation implements MilkTeaOperation {
    @Override
    public void execute(Scanner scanner) {
        System.out.println("请输入奶茶名称:");
        String product_name = scanner.nextLine();

        double price = 0.0;
        while (true) {
            System.out.println("请输入售价:");
            try {
                price = Double.parseDouble(scanner.nextLine());
                if (price > 0) {
                    break;
                } else {
                    System.out.println("售价必须大于0，请重新输入。");
                }
            } catch (NumberFormatException e) {
                System.out.println("输入的售价格式不正确，请重新输入。");
            }
        }

        double inprice = 0.0;
        while (true) {
            System.out.println("请输入进价:");
            try {
                inprice = Double.parseDouble(scanner.nextLine());
                if (inprice > 0) {
                    break;
                } else {
                    System.out.println("进价必须大于0，请重新输入。");
                }
            } catch (NumberFormatException e) {
                System.out.println("输入的进价格式不正确，请重新输入。");
            }
        }

        System.out.println("请输入描述:");
        String description = scanner.nextLine();

        MilkTeaProduct milkTeaProduct = new MilkTeaProduct(0, product_name, price, inprice, 0, description);
        MilkDao milk_dao = new MilkDao();
        milk_dao.addProduct(milkTeaProduct);
        System.out.println("新品奶茶添加成功");
    }
}
